home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / demohandler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  3.9 KB  |  194 lines

  1. #include <stdio.h>
  2. #include <libraries/dos.h>
  3.  
  4.  
  5. int   *vkadump;
  6. int   maxspclen;
  7. int   *manyptr;
  8. APTR  *libptr;
  9.  
  10. int finish = 0;
  11.  
  12. CallInit()
  13. {
  14. FILE *fp;
  15.  
  16. fp = fopen("RAM:MCAinit","r");
  17. if(fp == NULL) {
  18.    Help("There is no routine RAM:MCAinit !\n");
  19.    return;
  20. }
  21. fclose(fp);
  22. SysCall("RAM:MCAinit");
  23. }
  24.  
  25. ReadMCA()
  26. {
  27. FILE *fp;
  28.  
  29. fp = fopen("RAM:ReadMCA","r");
  30. if(fp == NULL) {
  31.    Help("There is no routine RAM:ReadMCA !\n");
  32.    return;
  33. }
  34. fclose(fp);
  35. SysCall("RAM:ReadMCA");
  36. }
  37.  
  38. WriteMCA()
  39. {
  40. FILE *fp;
  41.  
  42. fp = fopen("RAM:WriteMCA","r");
  43. if(fp == NULL) {
  44.    Help("There is no routine RAM:WriteMCA !\n");
  45.    return;
  46. }
  47. fclose(fp);
  48. SysCall("RAM:WriteMCA");
  49. }
  50.  
  51. ADC_ON()
  52. {
  53. FILE *fp;
  54.  
  55. fp = fopen("RAM:ADC_ON","r");
  56. if(fp == NULL) {
  57.    Help("There is no routine RAM:ADC_ON !\n");
  58.    return;
  59. }
  60. fclose(fp);
  61. SysCall("RAM:ADC_ON");
  62. }
  63.  
  64. ADC_OFF()
  65. {
  66. FILE *fp;
  67.  
  68. fp = fopen("RAM:ADC_OFF","r");
  69. if(fp == NULL) {
  70.    Help("There is no routine RAM:ADC_OFF !\n");
  71.    return;
  72. }
  73. fclose(fp);
  74. SysCall("RAM:ADC_OFF");
  75. }
  76.  
  77. MCA_exit()
  78. {
  79. finish = 1;
  80. }
  81.  
  82.  
  83. main(argc,argv)
  84. int argc;
  85. char *argv[];
  86. {
  87. int n,i;
  88. char s[80];
  89.  
  90.    if(argc != 5) {
  91.       fprintf(stderr,"Sorry, this programm must be started from MCAah!\n");
  92.       fprintf(stderr,"You can change the entry \"HANDLER=\" in the Tooltypes\n");
  93.       fprintf(stderr,"of MCAah to \"HANDLER=DemoHandler\"\n");
  94.       fprintf(stderr,"This allows you to have 5 separate \"stupid\" programs\n");
  95.       fprintf(stderr,"in RAM: which will be started to communicate with your\n");
  96.       fprintf(stderr,"Hardware. These programms are:\n");
  97.       fprintf(stderr,"RAM:MCAinit         to do some initialization\n");
  98.       fprintf(stderr,"RAM:ReadMCA         to read out the Hardware\n");
  99.       fprintf(stderr,"RAM:WriteMCA        to write back an old spectrum\n");
  100.       fprintf(stderr,"RAM:ADC_ON          to start a new measurement\n");
  101.       fprintf(stderr,"RAM:ADC_OFF         to stop your measurement\n");
  102.       fprintf(stderr,"There are two Amiga environment variables, which\n");
  103.       fprintf(stderr,"you will need:\n");
  104.       fprintf(stderr,"env:VKADUMP         contains the Hex address of\n");
  105.       fprintf(stderr,"                    the \"Display\" Buffer of MCAah\n");
  106.       fprintf(stderr,"env:MAXSPCLEN       contains the length of this buffer\n");
  107.       exit(0);
  108.    }
  109.    vkadump = (int *) xtoi(argv[1]);    /* reading buffer address */
  110.    maxspclen = atoi(argv[2]);          /* length of buffer */
  111.    manyptr = (int *) xtoi(argv[3]);    /* hardware address */
  112.    libptr = (APTR *) xtoi(argv[4]);    /* "library" pointer */
  113.    libptr[0] = (APTR) *ReadMCA;        /* fill in routines */
  114.    libptr[1] = (APTR) *WriteMCA;
  115.    libptr[2] = (APTR) *ADC_ON;
  116.    libptr[3] = (APTR) *ADC_OFF;
  117.    libptr[4] = (APTR) *MCA_exit;
  118.  
  119.    setenv2("VKADUMP",argv[1]);
  120.    setenv2("MAXSPCLEN",argv[2]);
  121.  
  122.    CallInit();
  123.  
  124. /* now going to endless loop */
  125.    finish = 0;
  126.    while(finish == 0) Delay(100L);
  127. }
  128.  
  129.  
  130. SysCall(str)
  131. char *str;
  132. {
  133. int i,n,m;
  134. struct FileHandle *input, *output;
  135. FILE *fp;
  136.  
  137. fp = fopen("c:runback","r"); /* check for existance of c:runback */
  138. if(fp == NULL) {
  139.    Help("Sorry, you don't have RUNBACK\nin your c: path.\nThis way you will not\nhave much fun with me\n");
  140.    return;
  141. }
  142. fclose(fp);
  143.  
  144. input = (struct FileHandle *) Open("nil:",MODE_OLDFILE);
  145. output = (struct FileHandle *) Open("nil:",MODE_NEWFILE);
  146.    Execute(str,input,output);
  147. Close(input);
  148. Close(output);
  149. }
  150.  
  151. xtoi(s)
  152. char s[];
  153. {
  154. int i,m,l,e;
  155. char c;
  156.  
  157.    l=strlen(s); e=0;
  158.    for(i=0;i<l;i++) {
  159.       c=s[i]; c = toupper(c);
  160.       m=c-'0';
  161.       if(m>9) m=m-7;
  162.       e=16*e+m;
  163.    }
  164.    return(e);
  165. }
  166.  
  167. setenv2(var,val)
  168. char *var;
  169. char *val;
  170. {
  171. FILE *fp;
  172. char *s;
  173. int n,m,i;
  174.  
  175.    s = (char *) malloc(80);
  176.    strcpy(s,"env:"); strcat(s,var);
  177.    fp = fopen(s,"w");
  178.    if(fp != NULL) {
  179.       fprintf(fp,"%s\n",val);
  180.       fclose(fp);
  181.    }
  182.    free(s);
  183. }
  184.  
  185. Help(s)
  186. char *s;
  187. {
  188. FILE *fp1;
  189.  
  190.    fp1 = fopen("con:30/30/400/50/Message from DemoHandler:","r+");
  191.    fprintf(fp1,"\n  %s",s);
  192.    Delay(200);
  193.    fclose(fp1);
  194. }